package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/07/06 11:54
 */
@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(beanName + ":BeanPostProcessor的before");
        if (bean instanceof LifeCycleBean) {
            ((LifeCycleBean)bean).setUsername("songge");
            return bean;
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println(beanName + ":BeanPostProcessor的after");
        return bean;
    }
}
